﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using VirtualPress.Tool.Framework;

namespace VirtualPress.Infrastructure.Entities.Repository
{
    [Table("T_Periodical")]
    public class T_Periodical : IEntity<T_Periodical>
    {
        [Key]
        [DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }
        /// <summary>
        /// 期刊类型
        /// 1：学术期刊  2：非学术期刊
        /// </summary>
        public int Type { get; set; }
        /// <summary>
        /// 稿件编号规则
        /// </summary>
        [Column(TypeName = "varchar")]
        [StringLength(128)]
        public string Manuscriptcode { get; set; }
        /// <summary>
        /// 行业分类
        /// </summary>
        public int IndType { get; set; }
        /// <summary>
        /// 出版社_Id
        /// </summary>
        public int Press_Id { get; set; }
        /// <summary>
        /// 期刊名称
        /// </summary>
        [Column(TypeName = "nvarchar")]
        [StringLength(64)]
        public string Name { get; set; }
        /// <summary>
        /// 期刊英文名
        /// </summary>
        [Column(TypeName = "varchar")]
        [StringLength(256)]
        public string Name_EN { get; set; }
        /// <summary>
        /// 期刊缩写
        /// </summary>
        [Column(TypeName = "nvarchar")]
        [StringLength(128)]
        public string ShortName { get; set; }
        /// <summary>
        /// 管理员账户
        /// </summary>
        [Column(TypeName = "nvarchar")]
        [StringLength(64)]
        public string Admin { get; set; }
        /// <summary>
        /// 出版周期
        /// </summary>
        public int PubRate { get; set; }
        /// <summary>
        /// 出版时间
        /// </summary>
        public string PubTime { get; set; }
        /// <summary>
        /// 创刊日期
        /// </summary>
        public DateTime FoundTime { get; set; }
        /// <summary>
        /// 主管单位
        /// </summary>
        [Column(TypeName = "nvarchar")]
        [StringLength(64)]
        public string ZGDW { get; set; }
        /// <summary>
        /// 主管单位_EN
        /// </summary>
        [Column(TypeName = "varchar")]
        [StringLength(256)]
        public string ZGDW_EN { get; set; }
        /// <summary>
        /// 主持单位
        /// </summary>
        [Column(TypeName = "nvarchar")]
        [StringLength(64)]
        public string ZCDW { get; set; }
        /// <summary>
        /// 主持单位_EN
        /// </summary>
        [Column(TypeName = "varchar")]
        [StringLength(256)]
        public string ZCDW_EN { get; set; }
        /// <summary>
        /// 主办单位
        /// </summary>
        [Column(TypeName = "nvarchar")]
        [StringLength(64)]
        public string ZBDW { get; set; }
        /// <summary>
        /// 主办单位_EN
        /// </summary>
        [Column(TypeName = "varchar")]
        [StringLength(256)]
        public string ZBDW_EN { get; set; }
        /// <summary>
        /// 协办单位
        /// </summary>
        [Column(TypeName = "nvarchar")]
        [StringLength(64)]
        public string XBDW { get; set; }
        /// <summary>
        /// 协办单位_EN
        /// </summary>
        [Column(TypeName = "varchar")]
        [StringLength(256)]
        public string XBDW_EN { get; set; }
        /// <summary>
        /// 出版单位
        /// </summary>
        [Column(TypeName = "nvarchar")]
        [StringLength(64)]
        public string CBDW { get; set; }
        /// <summary>
        /// 出版单位_EN
        /// </summary>
        [Column(TypeName = "varchar")]
        [StringLength(256)]
        public string CBDW_EN { get; set; }
        /// <summary>
        /// 高级顾问
        /// </summary>
        [Column(TypeName = "nvarchar")]
        [StringLength(64)]
        public string GJGW { get; set; }
        /// <summary>
        /// 高级顾问_EN
        /// </summary>
        [Column(TypeName = "varchar")]
        [StringLength(256)]
        public string GJGW_EN { get; set; }
        /// <summary>
        /// 编审顾问
        /// </summary>
        [Column(TypeName = "nvarchar")]
        [StringLength(64)]
        public string BSGW { get; set; }
        /// <summary>
        /// 编审顾问_EN
        /// </summary>
        [Column(TypeName = "varchar")]
        [StringLength(256)]
        public string BSGW_EN { get; set; }
        /// <summary>
        /// 主编
        /// </summary>
        [Column(TypeName = "nvarchar")]
        [StringLength(64)]
        public string Editor { get; set; }
        /// <summary>
        /// 主编英文名
        /// </summary>
        [Column(TypeName = "varchar")]
        [StringLength(256)]
        public string Editer_EN { get; set; }
        /// <summary>
        /// 发行范围
        /// </summary>
        [Column(TypeName = "nvarchar")]
        [StringLength(256)]
        public string Range { get; set; }
        /// <summary>
        /// 国际标准连续出版物号
        /// </summary>
        [Column(TypeName = "varchar")]
        [StringLength(256)]
        public string GJBZLXCBWH { get; set; }
        /// <summary>
        /// 国内统一连续出版物号
        /// </summary>
        [Column(TypeName = "varchar")]
        [StringLength(256)]
        public string GNTYLXCBWH { get; set; }
        /// <summary>
        /// 邮发代号
        /// </summary>
        [Column(TypeName = "varchar")]
        [StringLength(256)]
        public string YFDH { get; set; }
        /// <summary>
        /// 期刊简介
        /// </summary>
        [Column(TypeName = "text")]
        public string Introduction { get; set; }
        /// <summary>
        /// 期刊简介_EN
        /// </summary>
        [Column(TypeName = "text")]
        public string Introduction_EN { get; set; }
        /// <summary>
        /// 作者须知
        /// </summary>
        [Column(TypeName = "text")]
        public string Attention { get; set; }
        /// <summary>
        /// 征稿启事
        /// </summary>
        [Column(TypeName = "text")]
        public string CallForPaper { get; set; }
        /// <summary>
        /// 征稿启事_EN
        /// </summary>
        [Column(TypeName = "text")]
        public string CallForPaper_EN { get; set; }
        /// <summary>
        /// 注册时间
        /// </summary>
        public DateTime RegTime { get; set; }
        /// <summary>
        /// ISSN Print
        /// </summary>
        [Column(TypeName = "varchar")]
        [StringLength(256)]
        public string ISSN_Print { get; set; }
        /// <summary>
        /// ISSN Online
        /// </summary>
        [Column(TypeName = "varchar")]
        [StringLength(256)]
        public string ISSN_Online { get; set; }
        /// <summary>
        /// 期刊邮箱
        /// </summary>
        [Column(TypeName = "varchar")]
        [StringLength(256)]
        public string Email { get; set; }
        /// <summary>
        /// 检索信息
        /// </summary>
        [Column(TypeName = "nvarchar")]
        [StringLength(256)]
        public string Retrieval { get; set; }

        /// <summary>
        /// 期刊详情
        /// </summary>
        [Column(TypeName = "text")]
        public string Detail { get; set; }
        /// <summary>
        /// 期刊封面
        /// </summary>
        [Column(TypeName = "nvarchar")]
        [StringLength(256)]
        public string CoverImg { get; set; }
        public int VisitNumber { get; set; }
        public int DownloadNumber { get; set; }
        /// <summary>
        /// 是否上线
        /// </summary>
        [Column(TypeName = "bit")]
        public bool IsActive { get; set; }
        /// <summary>
        /// 稿件模板
        /// </summary>
        [Column(TypeName = "nvarchar")]
        [StringLength(256)]
        public string ManuscriptTemplete { get; set; }
        /// <summary>
        /// 审稿单
        /// </summary>
        [Column(TypeName = "nvarchar")]
        [StringLength(256)]
        public string ExamineSheet { get; set; }
        /// <summary>
        /// 默认审回时间
        /// </summary>
        public int DefaultExamineDay { get; set; }
        public int ManuscriptPageSize { get; set; }
        /// <summary>
        /// 是否收取专审费
        /// </summary>
        [Column(TypeName = "bit")]
        public bool IsFeeForExpertExmaine { get; set; }
        public int PagePrice { get; set; }
        public int PricePerPrice { get; set; }
        /// <summary>
        /// 出版费
        /// </summary>
        public int PublicationPrice { get; set; }
        /// <summary>
        /// 征稿范围
        /// </summary>
        [Column(TypeName = "nvarchar")]
        [StringLength(1024)]
        public string ZGFW { get; set; }

        [Column(TypeName = "bit")]
        public bool IsNew { get; set; }
        public override T_Periodical Find(System.Linq.Expressions.Expression<Func<T_Periodical, bool>> where)
        {
            using (Context ctx = new Context())
            {
                var item = ctx.Periodical.FirstOrDefault(where);
                if (item != null)
                {
                    this.Type = item.Type;
                    this.Admin = item.Admin;
                    this.BSGW = item.BSGW;
                    this.BSGW_EN = item.BSGW_EN;
                    this.CallForPaper = item.CallForPaper;
                    this.CallForPaper_EN = item.CallForPaper_EN;
                    this.CBDW = item.CBDW;
                    this.CBDW_EN = item.CBDW_EN;
                    this.CoverImg = item.CoverImg;
                    this.DownloadNumber = item.DownloadNumber;
                    this.Editer_EN = item.Editer_EN;
                    this.Editor = item.Editor;
                    this.Email = item.Email;
                    this.FoundTime = item.FoundTime;
                    this.GJBZLXCBWH = item.GJBZLXCBWH;
                    this.GJGW = item.GJGW;
                    this.GJGW_EN = item.GJGW_EN;
                    this.GNTYLXCBWH = item.GNTYLXCBWH;
                    this.Id = item.Id;
                    this.IndType = item.IndType;
                    this.Introduction = item.Introduction;
                    this.Introduction_EN = item.Introduction_EN;
                    this.ISSN_Online = item.ISSN_Online;
                    this.ISSN_Print = item.ISSN_Print;
                    this.Manuscriptcode = item.Manuscriptcode;
                    this.Name = item.Name;
                    this.Name_EN = item.Name_EN;
                    this.ShortName = item.ShortName;
                    this.Press_Id = item.Press_Id;
                    this.PubRate = item.PubRate;
                    this.PubTime = item.PubTime;
                    this.Range = item.Range;
                    this.RegTime = item.RegTime;
                    this.Retrieval = item.Retrieval;
                    this.Detail = item.Detail;
                    this.VisitNumber = item.VisitNumber;
                    this.XBDW = item.XBDW;
                    this.XBDW_EN = item.XBDW_EN;
                    this.YFDH = item.YFDH;
                    this.ZBDW = item.ZBDW;
                    this.ZBDW_EN = item.ZBDW_EN;
                    this.ZCDW = item.ZCDW;
                    this.ZCDW_EN = item.ZCDW_EN;
                    this.ZGDW = item.ZGDW;
                    this.ZGDW_EN = item.ZGDW_EN;
                    this.IsActive = item.IsActive;
                    this.Attention = item.Attention;
                    this.ManuscriptTemplete = item.ManuscriptTemplete;
                    this.IsFeeForExpertExmaine = item.IsFeeForExpertExmaine;
                    this.PagePrice = item.PagePrice;
                    this.DefaultExamineDay = item.DefaultExamineDay;
                    this.ManuscriptPageSize = item.ManuscriptPageSize;
                    this.PricePerPrice = item.PricePerPrice;
                    this.ZGFW = item.ZGFW;
                    this.ExamineSheet = item.ExamineSheet;
                    this.PublicationPrice = item.PublicationPrice;
                    this.IsNew = item.IsNew;
                    return this;
                }
                return null;
            }
        }
        public override T_Periodical Find(string key)
        {
            int id = Int32.Parse(key);
            return Find(c => c.Id == id);
        }
        public override bool Any(System.Linq.Expressions.Expression<Func<T_Periodical, bool>> where)
        {
            using (Context ctx = new Context())
            {
                return ctx.Periodical.Any(where);
            }
        }
    }
}